package wildlife;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMessage;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.*;

public class Login extends ActionSupport{
private String username,password;

public String getUsername() {
	return username;
}

public void setUsername(String username) {
	this.username = username;
}

public String getPassword() {
	return password;
}

public void setPassword(String password) {
	this.password = password;
}
public String execute(){
	try{
	Connect c=new Connect();
	ResultSet rs=c.getResult("select * from users where username='"+username+"' and password='"+password+"'");
	if(rs.next()){
		ResultSet rs1=c.getResult("select cstatus from users where username='"+rs.getString("username")+"'" );
		rs1.next();
		if(rs1.getInt("cstatus")!=1){
			addActionError("plz confirm your registration");
			return "fail";
		}
		HttpServletRequest request=ServletActionContext.getRequest();
		HttpSession session=request.getSession();
		session.setAttribute("username",username);
		System.out.println("username "+username+"password = "+password);
		if(username.equals("admin"))
		{
			return "admin";
		}
		return "success";
		
	}
	else{
		addActionError("invalid username/password");
		return "fail";
	}
	}catch(Exception e){e.printStackTrace();return "error";}
	
	
}
	
	
}

